package adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.layout.GridLayoutHelper;

import net.ck.hzq.R;

import java.util.ArrayList;
import java.util.List;

import Utils.ScreenUtil;
import dao.AllyRewardCustomItem;

/**
 * by BF00233 on 2018/12/21.
 */
public class AllyRewardItemAdapter extends DelegateAdapter.Adapter<AllyRewardItemAdapter.MonthVH> {

    private final Context mContext;
    private List<AllyRewardCustomItem> mData;

    public AllyRewardItemAdapter(Context context) {
        mContext = context;
        mData = new ArrayList<>();
    }

    public void setupData(List<AllyRewardCustomItem> data) {
        mData.clear();
        if (data != null) {
            mData.addAll(data);
        }
        notifyDataSetChanged();
    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        GridLayoutHelper layoutHelper = new GridLayoutHelper(1);
        layoutHelper.setVGap(ScreenUtil.dip2px(mContext, 5));
        return layoutHelper;
    }

    @NonNull
    @Override
    public MonthVH onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new MonthVH(LayoutInflater.from(mContext).inflate(R.layout.item_ally_reward, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull MonthVH holder, int position) {
        if (position < 0 || position >= mData.size()) {
            return;
        }
        AllyRewardCustomItem item = mData.get(position);
        holder.allyName.setText("合伙人姓名：" + item.customName);
        holder.totalAmount.setText(item.dividedAmount);
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    class MonthVH extends RecyclerView.ViewHolder {
        private TextView allyName;
        private TextView totalAmount;

        MonthVH(@NonNull View itemView) {
            super(itemView);
            allyName = itemView.findViewById(R.id.ally_name);
            totalAmount = itemView.findViewById(R.id.total_amount);
        }
    }

}
